/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A
 * copy of the license can be found at http://go.microsoft.com/fwlink/?LinkID=131993. If
 * you cannot locate the Microsoft Public License, please send an email to
 * mixon@microsoft.com. By using this source code in any fashion, you are agreeing to
 * be bound by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace MIXOnline.Descry
{
    public partial class Page : UserControl
    {
        bool bNeedsToLoadSource = true;

        public Page()
        {
            InitializeComponent();

            amsi.HelpClicked += new EventHandler<EventArgs>(amsi_HelpClicked);

            // has help screen been shown to use for first time?
            bool? result = Storage.GetAppSettingItem("ShowStartupScreens") as bool?;

            if (result != null)
            {
                if (result.Value)
                    gridHelp.Visibility = Visibility.Collapsed;

                // Start up AttachableMultiScaleImage
                amsi.BeginLoadingSource(false);
                bNeedsToLoadSource = false;
            }
        }

        void amsi_HelpClicked(object sender, EventArgs e)
        {
            gridHelp.Visibility = Visibility.Visible;
            gridHelpFadeIn.Begin();
        }

        #region Events

        private void explore_button_MouseLeftButtonUp (object sender, RoutedEventArgs e)
        {
            // get state of checkbox and persist in IS
            Storage.SetAppSettingItem("ShowStartupScreens", checkboxHideStartupScreens.IsChecked.Value);

            // Hide UX grid
            gridHelpFadeOut.Begin();

            // Start up AttachableMultiScaleImage
            if (bNeedsToLoadSource)
            {
                amsi.BeginLoadingSource(false);
                bNeedsToLoadSource = false;
            }
            else
            {
                //amsi.GoHome();
                //amsi.TrackAnimation();
            }
        }

        private void tour_button_MouseLeftButtonUp(object sender, RoutedEventArgs e)
        {

            // get state of checkbox and persist in IS
            Storage.SetAppSettingItem("ShowStartupScreens", checkboxHideStartupScreens.IsChecked.Value);

            // Hide UX grid
            gridHelpFadeOut.Begin();

            // begin tour by going to "a" process marker.
            if (bNeedsToLoadSource)
            {
                amsi.BeginLoadingSource(true);
                bNeedsToLoadSource = false;
            }
            else
                amsi.StartTour();

        }

        private void buttonCloseHelp_Click(object sender, RoutedEventArgs e)
        {
            // fade pages to transparent.
            gridHelp.Visibility = Visibility.Collapsed;

            // Start up AttachableMultiScaleImage
            if (bNeedsToLoadSource)
            {
                amsi.BeginLoadingSource(false);
                bNeedsToLoadSource = false;
            }
        }

        #endregion Events

        private void help_image_MouseEnter(object sender, MouseEventArgs e)
        {
            (sender as Image).Opacity = 1.0;
        }

        private void help_image_MouseLeave(object sender, MouseEventArgs e)
        {
            (sender as Image).Opacity = .15;
        }

        private void help_button_MouseEnter(object sender, MouseEventArgs e)
        {
            (sender as Image).Opacity = 1.0;
            (sender as Image).Width += 5;
            (sender as Image).Height += 5;
        }

        private void help_button_MouseLeave(object sender, MouseEventArgs e)
        {
            (sender as Image).Opacity = .50;
            (sender as Image).Width -= 5;
            (sender as Image).Height -= 5;
        }

    }
}
